package com.vpx.server.mapper.system;

import com.vpx.server.bean.entity.SysAttach;
import com.vpx.server.framework.base.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author denglw
 * @title: vpx
 * @module TODO
 * @description: TODO
 * @date 2021/9/16 10:39
 */
public interface SysAttachMapper extends BaseMapper<SysAttach> {
	/**
	 * 查找附件
	 * @param attachId
	 * @return
	 */
    @Select("select * from sys_attach where attach_id = #{attachId}")
    SysAttach findByAttachId(@Param("attachId") String attachId);

    /**
     * 查询多个
     * @param attachIds
     * @return
     */
    @Select("<script>select * from sys_attach where attach_id in \n" +
            "<foreach collection='attachIds' item='item' open='(' close=')' separator=','>#{item}</foreach>\n" +
            "</script>")
    List<SysAttach> findByAttachIds(@Param("attachIds") List<String> attachIds);
    
    
    @Select("select * from sys_attach where attach_id in (select t.check_sign_img_id from (select check_sign_img_id from ${tableName} where match_device_detail_id=#{matchDeviceDetailId} and task_id=#{taskId} and task_process_id=#{taskProcessId} and task_procedure_id=#{taskProcedureId}  and check_sign_img_id is not null order by check_sign_time desc limit 1) t) limit 1")
    SysAttach findCheckByTaskProcessAndTaskProcedureAndMatchDeviceDetailId(@Param("tableName") String tableName,@Param("taskId") Long taskId,@Param("taskProcessId") Long taskProcessId, @Param("taskProcedureId") Long taskProcedureId, @Param("matchDeviceDetailId") Long matchDeviceDetailId); 
    @Select("select * from sys_attach where attach_id in (select t.mutual_sign_img_id from (select mutual_sign_img_id from ${tableName} where match_device_detail_id=#{matchDeviceDetailId} and task_id=#{taskId} and task_process_id=#{taskProcessId} and task_procedure_id=#{taskProcedureId}  and mutual_sign_img_id is not null order by mutual_sign_time desc limit 1) t) limit 1")
    SysAttach findMutualByTaskProcessAndTaskProcedureAndMatchDeviceDetailId(@Param("tableName") String tableName,@Param("taskId") Long taskId,@Param("taskProcessId") Long taskProcessId, @Param("taskProcedureId") Long taskProcedureId, @Param("matchDeviceDetailId") Long matchDeviceDetailId); 
    @Select("select * from sys_attach where attach_id in (select t.test_sign_img_id from (select test_sign_img_id from ${tableName} where match_device_detail_id=#{matchDeviceDetailId} and task_id=#{taskId} and task_process_id=#{taskProcessId} and task_procedure_id=#{taskProcedureId}  and test_sign_img_id is not null order by test_sign_time desc limit 1) t) limit 1")
    SysAttach findTestByTaskProcessAndTaskProcedureAndMatchDeviceDetailId(@Param("tableName") String tableName,@Param("taskId") Long taskId,@Param("taskProcessId") Long taskProcessId, @Param("taskProcedureId") Long taskProcedureId, @Param("matchDeviceDetailId") Long matchDeviceDetailId); 
}
